package com.tutu.service.impl;

import com.tutu.core.api.ModuleApiUrls;
import com.tutu.service.ModuleService;
import com.tutu.utils.HttpRequestUtil;
import com.tutu.utils.UnicodeUtil;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * ModuleServiceImpl
 */
@Service
public class ModuleServiceImpl implements ModuleService {

    @Override
    public Map<String, Object> pageByParams(String keyWord, Integer pageNum, Integer pageSize) {
        return HttpRequestUtil.getOnlyData(ModuleApiUrls.base_prefix + ModuleApiUrls.page, "keyWord=" + UnicodeUtil.unicodeEncode(keyWord) + "&pageNum=" + pageNum + "&pageSize=" + pageSize);
    }

    @Override
    public Map<String, Object> saveInfo(HttpServletRequest request, Integer id, String name, String liName, String description, Integer sortIndex) {
        LogInfoServiceImpl.saveLogInfo(request, "编辑菜单信息，ID：" + id + "，名称：" + name + "，别名：" + liName + "，图标：" + description + "，顺序：" + sortIndex);

        String url = ModuleApiUrls.base_prefix + ModuleApiUrls.update;

        if (null == id) url = ModuleApiUrls.base_prefix + ModuleApiUrls.create;

        return HttpRequestUtil.getCompleteData(url, "id=" + id + "&sortIndex=" + sortIndex + "&name=" + UnicodeUtil.unicodeEncode(name) + "&description=" + UnicodeUtil.unicodeEncode(description) + "&liName=" + UnicodeUtil.unicodeEncode(liName));
    }

    @Override
    public Map<String, Object> deleteById(HttpServletRequest request, Integer id) {
        LogInfoServiceImpl.saveLogInfo(request, "删除菜单信息，ID：" + id);

        return HttpRequestUtil.getCompleteData(ModuleApiUrls.base_prefix + ModuleApiUrls.delete, "id=" + id);
    }

    @Override
    public Map<String, Object> batchDel(HttpServletRequest request, String ids) {
        LogInfoServiceImpl.saveLogInfo(request, "批量删除菜单信息，IDS：" + ids);

        return HttpRequestUtil.getCompleteData(ModuleApiUrls.base_prefix + ModuleApiUrls.batchDel, "ids=" + ids);
    }
}
